package v1

import (
	"github.com/gin-gonic/gin"
	"github.com/spf13/cast"
	"hr/api/dto"
	"hr/db"
	"hr/utils"
)

// GetApprovalRecord
// @Summary 获取审批记录
// @Tags 审批记录相关api
// @Accept  json
// @Produce json
// @Param Access-Token header string true "Authentication header"
// @Param pageNo query string true "页码"
// @Param pageSize query string true "页大小"
// @Param name query string false "名称"
// @Param no query string false "编号"
// @Param type query string false "审批类型"
// @Success 200 {object} utils.JsonContent
// @Failure 400 {object} utils.JsonContent
// @Failure 500 {object} utils.JsonContent
// @Router /api/v1/auth/approval_record [get]
func GetApprovalRecord(c *gin.Context)  {
	pageNoStr := c.Query("pageNo")
	pageSizeStr := c.Query("pageSize")
	name := c.Query("name")
	no := c.Query("no")
	types := c.Query("type")

	var pageNo,pageSize int
	if !utils.IsStringEmpty(pageNoStr) {
		pageNo = cast.ToInt(pageNoStr)
	}
	if !utils.IsStringEmpty(pageSizeStr) {
		pageSize = cast.ToInt(pageSizeStr)
	}
	paging := &dto.Pagination{
		PageNo:  pageNo,
		PageSize: pageSize,
	}

	d, err := db.GetApprovalRecordPaging(*paging, name, no, types)
	if err != nil {
		utils.EchoError(c, err.Error())
		return
	}
	utils.EchoSuccess(c, d, "请求成功")
	return
}
